﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Xml;
using S3_Sync_Library;
using System.IO;

/*
 
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            return;
            //Sample Test Code
            this.client = new S3Client("AKIAIAKLCNN6JWVRETSA", "bq9aXJ4ecXpWD7lCX5oPS6mJ85ygqAriJVXhvx3S");

            List<S3Bucket> buckets1 = this.client.ListBuckets();

            this.client.CreateBucket("OMGWTFBBQAWSCAT", S3Region.US);

            List<S3Bucket> buckets2 = this.client.ListBuckets();

            List<S3Object> files1 = this.client.ListFiles("OMGWTFBBQAWSCAT");

            OpenFileDialog ofd = new OpenFileDialog();
            ofd.ShowDialog();

            
            this.client.UploadFile("OMGWTFBBQAWSCAT", ofd.FileName);

            List<S3Object> files2 = this.client.ListFiles("OMGWTFBBQAWSCAT");

            this.client.DownloadFile("OMGWTFBBQAWSCAT", "zues.txt");

            int i = 0;


        }
 */

namespace S3_Sync_Backup
{
    class S3SyncBackup
    {
        private S3Client client;

        public S3SyncBackup(String configFile)
        {
            S3SyncConfig config = new S3SyncConfig();
            config.AWSAccessKey = "AKIAIAKLCNN6JWVRETSA";
            config.AWSSecretKey = "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";
            config.Bucket = "DACMBUMONGEISMEANFOFOFO";
            config.S3Config.CommunicationProtocol = Amazon.S3.Model.Protocol.HTTP;
            config.IncludeFolders.Add(new IncludeFolder("c:\\Intel", SearchOption.AllDirectories));
            config.S3Config.MaxErrorRetry = 3;


            XmlSerializer xmlSerializer = new XmlSerializer(typeof(S3SyncConfig));

            XmlWriter xmlWriter = XmlWriter.Create(configFile);

            xmlSerializer.Serialize(xmlWriter, config);

            xmlWriter.Close();



            XmlSerializer xmlDeserializer = new XmlSerializer(typeof(S3SyncConfig));

            XmlReader xmlReader = XmlReader.Create(configFile);

            S3SyncConfig config2 = (S3SyncConfig)xmlDeserializer.Deserialize(xmlReader);

            xmlReader.Close();




            this.client = new S3Client(config2.AWSAccessKey, config2.AWSSecretKey, config2.S3Config);

            this.client.CreateBucket(config2.Bucket, Amazon.S3.Model.S3Region.US);

            foreach (IncludeFolder folder in config2.IncludeFolders)
            {
                foreach (String file in Directory.GetFiles(folder.folder, "", folder.includeSubFolders))
                {
                    Console.WriteLine(file);
                }
            }

            Console.ReadKey();
        }
    }
}
